
class AlterPage {
	//	Attributes
	String 	name
	String 	description
	String 	pathFile
	String 	extFile
	boolean rateable 	= true
	boolean commentable = true
	boolean disabled 	= false
	
	Date 	dateCreated
	Date 	lastUpdated

	
	//	Not Persistence Attributes
	static transients = ['rate', 'path', 'author']
	
	
	//	DB Relations & Constraits
	static belongsTo = 	[homePage:	Page, 
	                   	 createdBy:	User]
						 
	static hasMany =	[coments:	Comment,
	                	 ratings:	Rate]
	
	
	//	DB Constraits
	static 	constraints = {
		name(blank:false, unique:true, maxSize:50)
		description(nullable:true, maxSize:1000)
	}
	
	//	Other Methods
	String getRate() {
		//	Calculem la mitja de les puntuacions rebudes fins ara
		Float p = 0
		if(ratings){
			ratings.each(){ p += it.rate }
			p = p / ratings.count()
		}
		return p	//TODO: comprvar si esta linea hace falta
	}
	
	String getPath () {
		return "none"
	}
}